using System;
using ScenarioFramework.WorkflowEngine.DataModel;

namespace ScenarioFramework.WorkflowEngine.DataModel.WorkflowProcesses
{
	public class XMLBehaviour : bOSdotNET.XML.Data.XMLObject
	{
		public const string MAIN_NODE				= "Behaviour";

		private XMLBehaviourStart start;
		private XMLBehaviourFinish finish;
		private XMLBehaviourExecution execution;

		/** CONSTRUCTOR Width simple Property **/
		public XMLBehaviour()
		{
			this.Init();
		}

		/** CONSTRUCTOR Width xml parsering**/
		public XMLBehaviour(System.Xml.XmlNode node)
		{
			this.Parse(node);
		}

		/** INSTANCE METHODS **/

		public XMLBehaviourStart XMLBehaviourStart
		{
			get { return start; }
			set { start = value; }
		}

		public XMLBehaviourFinish XMLBehaviourFinish
		{
			get { return finish; }
			set { finish = value; }
		}

		public XMLBehaviourExecution XMLBehaviourExecution
		{
			get { return execution; }
			set { execution = value; }
		}
		/** Inizializing method **/
		override public void Init()
		{
			start = new XMLBehaviourStart ();
			finish = new XMLBehaviourFinish ();
			execution = new XMLBehaviourExecution ();
		}

		/** Parsering method for filling the transition **/
		override public void Parse(System.Xml.XmlNode node2Parse)
		{
			this.Init();

			System.Xml.XmlNode node;

			/** find the sub tags witch contains values **/
			for ( int i=0; i<node2Parse.ChildNodes.Count; i++)
			{
				node = node2Parse.ChildNodes[i];

				switch ( node.Name )
				{
					case XMLBehaviourStart.MAIN_NODE:
						start.Parse(node);
						break;
					
					case XMLBehaviourFinish.MAIN_NODE:
						finish.Parse(node);
						break;

					case XMLBehaviourExecution.MAIN_NODE:
						execution.Parse(node);
						break;
				}
			}
		}

		override public bOSdotNET.XML.XMLNode GetXMLNode()
		{
			bOSdotNET.XML.XMLNode xmlNode = new bOSdotNET.XML.XMLNode(XMLBehaviour.MAIN_NODE);

			xmlNode.AddNode ( start.GetXMLNode());
			xmlNode.AddNode ( finish.GetXMLNode());
			xmlNode.AddNode ( execution.GetXMLNode());
			
			return xmlNode;
		}
	}
}
